package org.ezplatform.office.meeting.memo.dao;

import java.util.List;

import org.ezplatform.core.dao.jpa.JpaBaseDao;
import org.ezplatform.office.meeting.memo.entity.MemoUserInfo;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface MemoUserInfoDao extends JpaBaseDao<MemoUserInfo, String> {

    @Query(value = "from MemoUserInfo m where m.memoId=?1")
    List<MemoUserInfo> getMemoUserInfoList(String id);
    
    @Query(value = "from MemoUserInfo m where m.memoId=?1 and m.corpId=?2")
    List<MemoUserInfo> getMemoUserInfoByMemoId(String memoId, String corpId);

    @Query(value = "from MemoUserInfo m where m.memoId=?1 and m.memoUserId=?2 and m.corpId=?3")
    List<MemoUserInfo> getMemoUserInfo(String memoId, String userId, String corpId);
    
    @Query(value = "select m.memoUserId from MemoUserInfo m where m.memoId=?1 and m.memoUserId in (?2) and m.corpId=?3")
    List<String> getMemoUserInfo(String memoId, List<String> userIds, String corpId);
    
    @Query(value = "select count(id) from MemoUserInfo m where m.memoUserId=?1 and m.corpId=?2 and m.isView='0' ")
    int countMemoUserInfo(String userId, String corpId);
    
    @Modifying
    @Query(value = "delete from MemoUserInfo m where m.memoId=?1 and m.memoUserId not in(?2)")
    void deleteMemoUserInfo(String memoId, List<String> existList);

    @Modifying
    @Query(value = "delete MemoUserInfo m where m.memoId=?1")
    void deleteMemoUserInfo(String memoId);

    @Modifying
    @Query(value = "delete MemoUserInfo m where m.memoId in (?1)")
    void deleteMemoUserInfo(List<String> memoId);
    
    @Modifying
    @Query(value = "update MemoUserInfo m set m.isView=1 where m.memoId=?1 and m.memoUserId=?2")
    void updateMemoUserInfo(String memoId, String userId);
    
}